<script lang="ts" setup>
import { RoomVO } from '@/api/ecg/room'
import {PropType} from "vue";
import {useCheckTypeStore} from "@/store/modules/checkType";
import {UserVO} from "@/store/modules/user";

const emit = defineEmits(['event-haveseat', 'event-leaveseat', 'event-setcurseat'])

defineComponent({
  name: 'RoomBedSelect'
})

const  props = defineProps({
// defineProps({
  title: {
    type: Number,
    required: true
  },
  bedList: {
    type: Array as PropType<RoomVO[]>,
    required: true
  },
  curBed: {
    type: Object as PropType<RoomVO>,
    required: true
  },
  curUser: {
    type: Object as PropType<UserVO>,
    required: true
  }
})

const checkTypeStore = useCheckTypeStore();

const onHaveSeatclick = (newItem: RoomVO) => {
  emit('event-haveseat', newItem)
}
const onLeaveSeatclick = (curItem: RoomVO) => {
  emit('event-leaveseat', curItem)
}
const onSetCurSeatclick = (curItem: RoomVO) => {
  emit('event-setcurseat', curItem)
}

/** 初始化 **/
onMounted(() => {
    console.info(props.bedList)
})

</script>

<template>
  <el-card style="width: 200px" shadow="hover" >
    <template #header>{{bedList[0].roomName}}</template>
    <div v-for="(bedItem, index) in bedList" :key="index">
      <div class="deskwarp">

        <div v-for="(checkType, subIndex) in bedItem.checkTypes" :key="subIndex">
          {{checkTypeStore.getCheckTypeName(checkType)}}
        </div>
        <div>
          {{bedItem.opType === 1?"领用":""}}
          {{bedItem.opType === 2?"安装":""}}
        </div>

        <img
            v-if="bedItem.docId === null"
            src="@/assets/room/open.jpg"
            style="width: 100%"
            alt="无医生"
        />
        <img
            v-else
            src="@/assets/room/desk-doctor.jpeg"
            style="width: 100%"
            alt="有医生"
        />
        <div>{{bedItem.bedNo}} {{bedItem.docName}} {{bedItem.status === 30?"-暂停":""}}</div>
        <el-button v-if="bedItem.docId === null" @click = onHaveSeatclick(bedItem)>
           入座
        </el-button>
        <div v-if="bedItem.docId === curUser.id">
          <el-button @click = onLeaveSeatclick(bedItem)>
             离座
          </el-button>
          <span v-if="bedItem.roomId === curBed.roomId && bedItem.bedNo === curBed.bedNo" >
             当前
          </span>
          <el-button v-else @click = onSetCurSeatclick(bedItem)>
             设为当前
          </el-button>
        </div>
        <el-divider/>
      </div>
    </div>
  </el-card>
</template>

<style scoped lang="scss">
.card-title {
  font-size: 14px;
  font-weight: 600;

  &::before {
    position: relative;
    top: 8px;
    left: -5px;
    display: inline-block;
    width: 3px;
    height: 14px;
    //background-color: #105cfb;
    background: var(--el-color-primary);
    border-radius: 5px;
    content: '';
    transform: translateY(-50%);
  }
}

.deskwarp {
  display: flex;
  flex-direction: column;
  align-items: center;
  /*height: 260px;*/
}

</style>
